
#include <BHBoxLayout>

#include "BasicPanel.h"

BasicPanel::BasicPanel(BWidget* parent) : BGroupBox(parent)
{
	this->setTitleAlign(Align_Center);

	_foldButton = new BButton();
	_foldButton->setName("fold");
	_foldButton->setForm(Form_IconOnly);
	_foldButton->setGraph(Graph_Arrow_Right_Fill);
	_foldButton->setCheckable(true);

	BHBoxLayout* titleLayout = new BHBoxLayout();
	titleLayout->addWidget(_foldButton);
	titleLayout->addSpring();
	this->setLayout(titleLayout, Part_LeftTop);

	connect(this, Signal_Folded, &BasicPanel::slotFoled);
	connect(_foldButton, Signal_Toggled, &BasicPanel::slotFoldButtonToggled);
}
BasicPanel::~BasicPanel()
{

}

void BasicPanel::slotFoled()
{
	_foldButton->setChecked(this->folded());
}
void BasicPanel::slotFoldButtonToggled(BObject* object, const BValue& value)
{
	bool checked = value;
	this->setFolded(checked);
	if (checked)
		_foldButton->setGraph(Graph_Arrow_Down_Fill);
	else
		_foldButton->setGraph(Graph_Arrow_Right_Fill);
}
